package com.jeejam.product.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.Pager;
import com.jeejam.product.pojo.Attribute;
import com.jeejam.product.sdk.api.IAttributeService;
import com.jeejam.product.sdk.dto.AttributeDto;
import com.jeejam.product.service.AttributeService;
import com.jeejam.util.ShopBeanBuildUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/18.
 */
@Service(version = "1.0.0")
public class AttributeDubboService implements IAttributeService {

    @Resource
    private AttributeService attributeService;

    @Override
    public int counts() {
        return attributeService.counts();
    }

    @Override
    public Pager getPager(int currentPage, int pageSize) {
        return attributeService.getPager(currentPage, pageSize);
    }

    @Override
    public List<AttributeDto> findAllByPage(int currentPage, int pageSize) {
        List<Attribute> attributeList = attributeService.selectAllByPage(currentPage, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(attributeList, AttributeDto.class);
    }

    @Override
    public Pager getPagerByCounts(int counts, int currentPage, int pageSize) {
        return attributeService.getPagerByCounts(counts, currentPage, pageSize);
    }

    @Override
    public void deleteById(int id) {
        attributeService.deleteById(id);
    }

    @Override
    public AttributeDto getById(int id) {
        Attribute attribute = attributeService.findById(id);
        return ShopBeanBuildUtil.slmCopyBean(attribute, AttributeDto.class);
    }

    @Override
    public void save(AttributeDto attributeDto) {
        Attribute attribute = ShopBeanBuildUtil.slmCopyBean(attributeDto, Attribute.class);
        attributeService.save(attribute);
    }

    @Override
    public void update(AttributeDto attributeDto) {
        Attribute attribute = ShopBeanBuildUtil.slmCopyBean(attributeDto, Attribute.class);
        attributeService.update(attribute);
    }

    @Override
    public int getTotalPage(int counts, int pageSize) {
        return attributeService.getTotalPage(counts, pageSize);
    }

    @Override
    public List<AttributeDto> findByTypeId(int typeId) {
        List<Attribute> attributeList = attributeService.findByTypeId(typeId);
        return ShopBeanBuildUtil.slmCopyBeanList(attributeList, AttributeDto.class);
    }

    @Override
    public int countsByTypeId(int typeId) {
        return attributeService.countsByTypeId(typeId);
    }

    @Override
    public List<AttributeDto> findByTypeIdAndPage(int typeId, int page, int pageSize) {
        List<Attribute> attributeList = attributeService.findByTypeIdAndPage(typeId, page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(attributeList, AttributeDto.class);
    }
}
